package com.example.huffman;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {


    HuffmanCodingCore codingCore = new HuffmanCodingCore();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final EditText editTree = (EditText) findViewById(R.id.edit_build_code);
        Button btnTree = (Button) findViewById(R.id.button_build_code);
        btnTree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String code = editTree.getText().toString();
                codingCore.nativeBuildTree(code);
            }
        });


        final EditText editTrans = (EditText) findViewById(R.id.edit_transcoding);
        final TextView tvTransResult = (TextView) findViewById(R.id.txv_transcoding);
        Button buttonTrans = (Button) findViewById(R.id.button_transcoding);
        buttonTrans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String code = editTrans.getText().toString();
                String result = codingCore.nativeTranscoding(code);
                tvTransResult.setText(result);
            }
        });


        final TextView tvDecode = (TextView) findViewById(R.id.txv_decoding);
        Button buttonDecode = (Button) findViewById(R.id.button_decoding);
        final EditText editDecode = (EditText) findViewById(R.id.edit_decoding);
        buttonDecode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String code = editDecode.getText().toString();
                String result = codingCore.nativeDecoding(code);
                tvDecode.setText(result);

            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        codingCore.nativeRelease();
    }


}
